<?php

$config = Config::getInstance();

$controller = $config->currentController;

$withOperations = true;//false;
//if($_SESSION[SESSION_PERFIL_FUNC] == PERFIL_ADMINISTRADOR){
//    $withOperations = true;
//}

$equipes = $controller->getAllEquipes(TRUE);

if(!empty($equipes)){
    
    echo "<h3 class=\"title-form\"> Lista de Equipes </h3>";
    
    $headers = array( 
        "nome" => "Nome", 
        "loja" => "Loja",
        "lider" => "Líder"
    );
    
    if($withOperations) {
        $headers["operations"] = "Operações";
        $img_del = "<img src='".GRID_ICONS."remover.png"."' title='Remover Equipe'>";
        $img_edit = "<img src='".GRID_ICONS."editar.png"."' title='Editar Equipe'>";
        $img_view = "<img src='".GRID_ICONS."visualizar.png"."' title='Ver Equipe'>";
        for($i = 0, $l = count($equipes); $i < $l; $i++){
            $vars = get_object_vars($equipes[$i]);
            $link_del = "<a href='?op=del_equipe&equipe={$vars["id"]}' class='ask' ask='deletar' >$img_del</a>";
            $link_edit = "<a href='javascript:openEditEquipeMode({$vars["id"]})'>$img_edit</a>";
            $link_view = js_link("openViewDataMode('ajax.php?code=5037&equipe={$vars["id"]}&type=html')", $img_view);
            $vars["operations"] = "$link_del $link_edit $link_view";
            $equipes[$i] = (object) $vars;
        }
    }
    
    include_once LISTS."table-generic.php";
    
    $table = new GenericTable($headers, $equipes);
    $table->id = "lista-equipes";
    
    $table->draw();
    
} else {
    echo "<h3 class=\"title-form\"> Sem Equipes </h3>";
}
if(!empty($equipes)){
?>
<script>
dependencies.push(function(){
    
    var lTable = $("#lista-equipes").dataTable({
        "bPaginate" : true,
        "bJQueryUI" : true,
        "sPaginationType": "full_numbers",
        "aoColumns": [
             { "asSorting": [ "desc", "asc" ]},
             { "asSorting": [ "desc", "asc" ]},
             { "asSorting": [ "desc", "asc" ]},
             <?php if($withOperations){ ?>{ "asSorting": [] }, <?php } ?>
        ],
        "sScrollY": "250px",
        "bScrollCollapse": false
    });       

    lTable.$('tr').hover( function() {
        $(this).addClass('highlighted');
    }, function() {
       lTable.$('tr.highlighted').removeClass('highlighted');
    });
});
</script>
<?php } ?>